import React from 'react';
import {
    Button,
    Text,
    View,
    Image,
    StyleSheet,
    Dimensions,
    StatusBar,
    ActivityIndicator,
    FlatList,
    ScrollView,
    RefreshControl,
    Animated,
    TouchableHighlight,
    SectionList,
    TouchableOpacity,
    Modal, DeviceEventEmitter, Switch
} from 'react-native';
import Swiper from 'react-native-swiper';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import AsyncStorage from '@react-native-community/async-storage';
const { width, height } = Dimensions.get('window');
import Styles from './Styles';

import app from '../../../app.json';
import Ugame from '../../../Ugame';
import Httpc from "../../utils/Httpc";
import REQUEST from "../../../REQUEST";
import Football from "../../utils/Football";
import Utils from "../../utils/Utils";

export default class UserPush extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            lists: [],
        };

    }
    static navigationOptions = {
        title: '推送设置',
        //header: null,  //隐藏顶部导航栏
        //tabBarVisible: false, // 隐藏底部导航栏
        headerStyle: {
            backgroundColor: '#d0162e',
            paddingTop: 18,
        },
        headerTintColor: '#fff',
        headerTitleStyle: {

        },
    }
    componentDidMount() {
        this.getServerData(() => { });

    }
    getServerData(callback) {
        let _this = this;
        let params = {};
        let { lists } = this.state;
        params.token = Ugame.info.Token;
        Httpc.get(REQUEST.GetUserPush, params, (res) => {
            console.log(res);
            if (res.StatusCode == -2) {
                Ugame.clearInfo();
                this.props.navigation.navigate('Login');
                return;
            }
            if (res.StatusCode == 1) {
                _this.setState({
                    lists: res.Data[0]
                });
                callback();
            }
        })
    }
    _onEndReached() {
        this.getServerData(() => { });
    }
    _separator() {
        return <View style={{ height: 0.5, backgroundColor: '#ededed' }} />;
    }
    //TakePush 取票提醒,OutPush 出票提醒,WinPush中奖提醒,CancelPush撤单提醒,CashPush提现提醒,BonusPush派奖提醒
    switchValue = (e, item) => {
        let lists = this.state.lists;
        lists[item] = e;
        let params = {};
        params.token = Ugame.info.Token;
        params.filed = item;
        params.value = e ? 1 : 0;

        Httpc.postQueryJsonFromData(REQUEST.SetUserPush, params, function (res) {
            if (res.StatusCode == -2) {
                Ugame.clearInfo();
                this.props.navigation.navigate('Login');
                return;
            }
            if (res.StatusCode != 1) {
                return;
            }
            this.setState({
                lists: lists,
            });
        }.bind(this));
    }

    render() {
        let { lists } = this.state;
        return (
            <View style={Styles.container}>
                <StatusBar translucent={true} backgroundColor="transparent" />
                <View style={Styles.recommend_lists}>
                    <View style={{ flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', }}>
                        <Text style={{ color: '#333' }}>取票提醒</Text>
                    </View>
                    <Switch
                        // disabled={true}//是否可以响应,默认为false,true是无法点击
                        onTintColor='#f68b2c'  //开关打开时的背景颜色
                        thumbTintColor='#ffffff' //开关上原形按钮的颜色
                        tintColor='#cccccc' //关闭时背景颜色
                        style={{ height: 50 }}
                        value={lists.TakePush == 1 ? true : false}//默认状态
                        onValueChange={(e) => this.switchValue(e, 'TakePush')}
                    />
                </View>
                <View style={Styles.recommend_lists}>
                    <View style={{ flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', }}>
                        <Text style={{ color: '#333' }}>出票提醒</Text>
                    </View>
                    <Switch
                        // disabled={true}//是否可以响应,默认为false,true是无法点击
                        onTintColor='#f68b2c'  //开关打开时的背景颜色
                        thumbTintColor='#ffffff' //开关上原形按钮的颜色
                        tintColor='#cccccc' //关闭时背景颜色
                        style={{ height: 50 }}
                        value={lists.OutPush == 1 ? true : false}//默认状态
                        onValueChange={(e) => this.switchValue(e, 'OutPush')}
                    />
                </View>
                <View style={Styles.recommend_lists}>
                    <View style={{ flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', }}>
                        <Text style={{ color: '#333' }}>中奖提醒</Text>
                    </View>
                    <Switch
                        // disabled={true}//是否可以响应,默认为false,true是无法点击
                        onTintColor='#f68b2c'  //开关打开时的背景颜色
                        thumbTintColor='#ffffff' //开关上原形按钮的颜色
                        tintColor='#cccccc' //关闭时背景颜色
                        style={{ height: 50 }}
                        value={lists.WinPush == 1 ? true : false}//默认状态
                        onValueChange={(e) => this.switchValue(e, 'WinPush')}
                    />
                </View>
                <View style={Styles.recommend_lists}>
                    <View style={{ flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', }}>
                        <Text style={{ color: '#333' }}>撤单提醒</Text>
                    </View>
                    <Switch
                        // disabled={true}//是否可以响应,默认为false,true是无法点击
                        onTintColor='#f68b2c'  //开关打开时的背景颜色
                        thumbTintColor='#ffffff' //开关上原形按钮的颜色
                        tintColor='#cccccc' //关闭时背景颜色
                        style={{ height: 50 }}
                        value={lists.CancelPush == 1 ? true : false}//默认状态
                        onValueChange={(e) => this.switchValue(e, 'CancelPush')}
                    />
                </View>
                <View style={Styles.recommend_lists}>
                    <View style={{ flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', }}>
                        <Text style={{ color: '#333' }}>提现提醒</Text>
                    </View>
                    <Switch
                        // disabled={true}//是否可以响应,默认为false,true是无法点击
                        onTintColor='#f68b2c'  //开关打开时的背景颜色
                        thumbTintColor='#ffffff' //开关上原形按钮的颜色
                        tintColor='#cccccc' //关闭时背景颜色
                        style={{ height: 50 }}
                        value={lists.CashPush == 1 ? true : false}//默认状态
                        onValueChange={(e) => this.switchValue(e, 'CashPush')}
                    />
                </View>
                <View style={Styles.recommend_lists}>
                    <View style={{ flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', }}>
                        <Text style={{ color: '#333' }}>派奖提醒</Text>
                    </View>
                    <Switch
                        // disabled={true}//是否可以响应,默认为false,true是无法点击
                        onTintColor='#f68b2c'  //开关打开时的背景颜色
                        thumbTintColor='#ffffff' //开关上原形按钮的颜色
                        tintColor='#cccccc' //关闭时背景颜色
                        style={{ height: 50 }}
                        value={lists.BonusPush == 1 ? true : false}//默认状态
                        onValueChange={(e) => this.switchValue(e, 'BonusPush')}
                    />
                </View>
                <Text style={{color:'#333333',paddingLeft:12,paddingTop:30,paddingBottom:10}}>温馨提示</Text>
                <Text style={{color:'#969696',fontSize:12,paddingLeft:12,paddingBottom:10}}>1.网络未连接,无法接收消息提醒</Text>
                <Text style={{color:'#969696',fontSize:12,paddingLeft:12,paddingBottom:10}}>2.未开通提醒，无法接收消息提醒</Text>
                <Text style={{color:'#969696',fontSize:12,paddingLeft:12,paddingBottom:10}}>3.未登录或更换用户名,无法接收消息提醒</Text>
            </View>
        )
    }
}

